var ctx = $("#ctx").val();
$(function () {
    //注销
    $(".bottom button").click(function () {
        $.ajax({
            url: ctx + "/user/logout",
            type: "GET",
            success: function (data) {
                if (data.code == 0) {
                    mdui.snackbar({
                        message: "注销成功",
                        position: "top"
                    });
                    setTimeout(function () {
                        location.href = ctx + "/login";
                    }, 1000)
                } else {
                    mdui.snackbar({
                        message: data.msg,
                        position: "top"
                    });
                }
            }
        });
    });
    $(".upload-btn").click(function () {
        $("input[type='file']").trigger("click");
    });
    $("input[type='file']").change(function () {
        var formData = new FormData($(this));
        $.ajaxFileUpload({
            type: "post",
            url: ctx + "/user/uploadavatar",
            secureuri: false,
            fileElementId: 'avatar',
            dataType:"text",
            success: function (data) {
                //ajaxfileupload使用iframe+form的方式实现异步上传文件 无法直接解析body
                var json = $.parseJSON($(data).html());
                if(json.code==0){
                    location.reload();
                }else{
                    mdui.snackbar({
                        message: "上传失败",
                        position: "top"
                    });
                }
            }
        });
    });
});